﻿using System;
using System.IO;
using System.Diagnostics;
using fastCSharp;

namespace lastProcess
{
    class Program
    {
        static void Main(string[] args)
        {
            string file = null;
            FileInfo fileInfo = null;
            foreach (string arg in args)
            {
                if (arg.length() != 0)
                {
                    if (file == null)
                    {
                        file = arg;
                        if (!file.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) file += ".exe";
                    }
                    else
                    {
                        FileInfo currentFile = new FileInfo(arg.pathSuffix() + file);
                        if (currentFile.Exists && (fileInfo == null || fileInfo.LastWriteTime < currentFile.LastWriteTime))
                        {
                            fileInfo = currentFile;
                        }
                    }
                }
            }
            if (fileInfo != null)
            {
                ProcessStartInfo info = new ProcessStartInfo(fileInfo.FullName, null);
                info.UseShellExecute = true;
                info.WorkingDirectory = fileInfo.DirectoryName;
                Process.Start(info);
            }
        }
    }
}
